﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Bit.Art.Db
{
    public class DesignTimeExchangeDbFactory : IDesignTimeDbContextFactory<ExchangeDb>
    {
        public ExchangeDb CreateDbContext(string[] args)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .Build();
            var builder = new DbContextOptionsBuilder<ExchangeDb>();
            var connectionString = configuration.GetConnectionString("ExchangeDb");
            builder.UseMySql(connectionString);
            return new ExchangeDb(builder.Options);
        }
    }

    public class DesignTimeExchangeConfigDbFactory : IDesignTimeDbContextFactory<ExchangeConfigDb>
    {
        public ExchangeConfigDb CreateDbContext(string[] args)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .Build();
            var builder = new DbContextOptionsBuilder<ExchangeConfigDb>();
            var connectionString = configuration.GetConnectionString("ExchangeConfigDb");
            builder.UseMySql(connectionString);
            return new ExchangeConfigDb(builder.Options);
        }
    }
}
